Generated code - DbUtils functionality

Preface

Every SelfServicing generated set classes has one class which controls a couple of global settings for the application: DbUtils.cs/vb, located in the HelperClasses namespace. DbUtils is also the class used by the DAO classes to produce database specific objects, like ADO.NET connections and command objects, and perform low level stored procedure execution.

Below are the options it offers as static (shared) options.

Connection strings

The DbUtils class lets you set the global connection string to use for every connection to the database. This setting overrides the connection string read from the appSettings section in the .config file. Once the setting is set, every connection to the database uses the set connection string. You set the connection string to use at runtime using the following code:

// C#
DbUtils.ActualConnectionString = "Datasource=myserver;....";
' VB.NET
DbUtils.ActualConnectionString = "Datasource=myserver;...."

If you want to make the application use the connection string defined in the config file again, simply set the ActualConnectionString property to string.Empty.

Command timeouts

If you want to set the ADO.NET command timeout to a value other than the default of 30 seconds, use the DbUtils.CommandTimeOut property to set it to a different value. This will change the timeout immediately for all calls to the database.

note Note:
Firebird doesn't support command timeouts.

ArithAbort flag (SqlServer only)

If an entity is saved into a table which is part of an indexed view, SqlServer requires that SET ARITHABORT ON is specified prior to the actual save action. You can tell LLBLGen Pro to set that option, by calling the global method DbUtils.SetArithAbortFlag(bool) method. After each SQL statement a SET ARITHABORT OFF statement will be executed if the ArithAbort flag is set to true. Setting this flag affects all INSERT statements following the call to SetArithAbortFlag(), until you call that method again.

DQE Compatibility mode(SqlServer only)

With the arrival of SqlServer 2005 and its new features, it was required to make the SqlServer DQE be configurable so it could generate SQL which was optimal for the database type used. To set the compatibility mode of the SqlServer DQE in code, you can use the DbUtils method SetSqlServerCompatibilityLevel, as shown in the following example which sets the compatibility mode to SqlServer 2005:

// C#
DbUtils.SetSqlServerCompatibilityLevel( SqlServerCompatibilityLevel.SqlServer2005 );
' VB.NET
DbUtils.SetSqlServerCompatibilityLevel( SqlServerCompatibilityLevel.SqlServer2005 )

The different compatibility modes are: The default is SqlServer2000. The values 0, 1 or 2 have to be used when you're using the .config file parameter. See for more details about that parameter Generated code - Application configuration through .config files.

Setting the compatibility level controls the sequence retrieval logic to use by default (@@IDENTITY on Sqlserver 7 or SCOPE_IDENTITY() on 2000/2005), the ability to use NEWSEQUENTIALID() (SqlServer 2005) and the SQL produced for a paging query: a temptable approach is used on SqlServer 7 or 2000, and a CTE approach is used on SqlServer 2005.

LLBLGen Pro v2.6 documentation. ©2002-2008 Solutions Design